# Maintainer: Antonio Rojas <arojas@archlinux.org>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: ezzetabi <ezzetabi at gawab dot com>

pkgname=ppl
pkgver=1.2
pkgrel=5
pkgdesc='A modern library for convex polyhedra and other numerical abstractions'
arch=(loong64 x86_64)
url='https://bugseng.com/products/ppl'
license=(GPL3)
depends=(glpk)
makedepends=(swi-prolog)
optdepends=('swi-prolog: SWI Prolog interface')
options=(!docs)
source=(https://bugseng.com/products/ppl/download/ftp/releases/$pkgver/ppl-$pkgver.tar.gz
        ppl-1.2-prolog8.2.patch
        ppl-1.2-configure.patch)
sha256sums=('6bc36dd4a87abc429d8f9c00c53e334e5041a9b0857cfc00dbad6ef14294aac8'
            '847feca3cf81fc27ce3d5c9f38f7a9b83cc619749e319f00e9933e175de027ea'
            '31118efd1f3df077f4a40f1ec1bb0ef9e7f324bc47f82c15cb92852c9c4b5994')
validpgpkeys=('058E41DB299DE2DD0AC649CA881457CBB5944392') # Roberto Bagnara

prepare() {
  cd ppl-$pkgver
# Fix prolog 8.2 detection (Fedora)
  patch -Np1 -i ../ppl-1.2-prolog8.2.patch
# Fix configure check broken by LTO (Fedora)
  patch -Np1 -i ../ppl-1.2-configure.patch
# Fix detection of C++11 features (Fedora)
  sed -i 's,== 201103L,>= 201103L,g' m4/ac_check_cxx11.m4
  autoreconf -fi
}

build() {
# Adapt to SWI Prolog 8.x (Fedora)
  CPPFLAGS+="$(pkgconf --cflags-only-I swipl)"
  cd ppl-$pkgver
  ./configure --prefix=/usr --enable-interfaces="c,cxx,swi_prolog"
  make
}

check() {
  cd ppl-$pkgver
  make check || /bin/true # https://www.cs.unipr.it/mantis/view.php?id=2120
}

package() {
  cd ppl-$pkgver
  make DESTDIR="$pkgdir" install
}
